<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateVideoChatRecordsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('video_chat_records', ['comment' => '视频聊天记录表']);
        $table->addColumn('caller_id', 'integer', ['comment' => '发起者用户ID'])
              ->addColumn('receiver_id', 'integer', ['comment' => '接收者用户ID'])
              ->addColumn('caller_aid', 'integer', ['comment' => '发起者用户agoraid',  'default'=> 0])
              ->addColumn('receiver_aid', 'integer', ['comment' => '接收者用户agoraid', 'default'=>0])
              ->addColumn('channel_id', 'string', ['limit' => 64, 'comment' => '频道ID'])
              ->addColumn('caller_token', 'string', ['comment' => '呼叫者的进入频道token'])
              ->addColumn('receiver_token', 'string', ['comment' => '接受者的进入频道token'])
              ->addColumn('start_time', 'datetime', ['comment' => '开始时间'])
              ->addColumn('end_time', 'datetime', ['null' => true, 'comment' => '结束时间'])
              ->addColumn('duration', 'integer', ['default' => 0, 'comment' => '通话时长（秒）'])
              ->addColumn('status', 'enum', ['values' => ["calling", "declined", 'active', 'ended', 'missed'], 'default' => 'calling', 'comment' => '通话状态'])
              ->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '记录创建时间'])
              ->addColumn('updated_at', 'timestamp', ['null' => true, 'comment' => '记录更新时间'])
              ->create();
    }
}
